from typing import Optional

from pydantic import BaseModel
from datetime import datetime


class Permissions(BaseModel):
    code: int
    description: str


class UserInfo(BaseModel):
    username: str  # 用户名
    is_frozen: bool  # 是否冻结
    is_admin: bool  # 是否管理员
    avatar: Optional[str]  # 头像，可为空
    role: list[str] = None  # 所属角色列表
    permissions: list[Permissions] = None  # 权限列表
    create_at: datetime  # 注册时间


class Token(BaseModel):
    userInfo: UserInfo  # 用户信息
    access_token: str  # 授权许可
    token_type: str  # 授权类型


class RegisterId(BaseModel):
    id: int


class PermissionsId(BaseModel):
    id: int


class Register(BaseModel):
    username: str
    is_frozen: bool
    is_admin: bool
    avatar: Optional[str]
    password: str
    role: list[RegisterId]
    permissions: list[PermissionsId]


class CreateRole(BaseModel):
    name: str


class UserList(BaseModel):
    username: str
    is_frozen: bool
    is_admin: bool
    avatar: Optional[str]
    registration_time: datetime


class UpdateUserInfo(Register):
    username: str = None
    is_admin: bool = None
    is_frozen: bool = None
    password: str = None
    role: list[RegisterId] = None


class RegisterList(RegisterId):
    id: int


class PermissionsList(Permissions):
    id: int
